<template>
    <div class="all">
    <div class="head">
      <el-select v-model="value" clearable placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
      <div>
    <el-radio-group v-model="radio">
      <el-radio-button label="今天" ></el-radio-button>
      <el-radio-button label="本周"></el-radio-button>
      <el-radio-button label="本月"></el-radio-button>
    </el-radio-group>
  </div>
    </div>
     
 <el-table :data="list1.filter(data => !value || data.state.toLowerCase().includes(value.toLowerCase()))" 
    height="90%"
    stripe
    style="width: 100%;margin-left:2%">
        <el-table-column  width="100">
                 <template slot-scope="scope">
                     <img :src=img1  width="40" height="40"/>
                 </template>
            </el-table-column>
        <el-table-column prop="fentryclerk"  ></el-table-column>
        <el-table-column prop="fopinions" ></el-table-column>
        <el-table-column prop="finputtime" ></el-table-column>
        <el-table-column prop="state" ></el-table-column>
        <!-- <el-table-column fixed="right" >
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="deleteRow(scope.row)"
              type="text"
              size="small"
            >通知</el-button>
            <el-button
              @click.native.prevent="deleteRow(scope.row)"
              type="text"
              size="small"
            >查找</el-button>
            <el-button
              @click.native.prevent="deleteRow(scope.row)"
              type="text"
              size="small"
            >more</el-button>
          </template>
        </el-table-column> -->
      </el-table>

    </div>
    
</template>

<script>
import  { formatTime}   from '@/utils/index'
import img1 from "@/views/daohan1/Statistics/toux.jpg";
import { getFeedbacks} from "@/api/Statistics";
export default {
  data () {
    return {
      formatTime,
      img1,
      state:"",
      options: [{
        value: '进行中',
        label: '进行中'
      }, {
        value: '已完成',
        label: '已完成'
      }, {
        value: '驳回',
        label: '驳回'
      }], // 筛选项目状态
      list1: "",
      radio: '',
      value: '',
      timeOptions:'',
      list1a:[],
      list1b:[],
      list1c:[],
    }

  },
    mounted() {
    this.getdata1();
  },
     methods:{
       deleteRow(){
console.log("eee")
       },
     getdata1() {
      //获取问题表
      let data = async () => {
        try {
          let result = await getFeedbacks();
          
          if (result) {
            this.list1 = result;
            this.timeOptions = result
            console.log(this.timeOptions)
            this.loading = false;
            for(var i = 0;i<this.list1.length;i++){
              // this.list1[i].finputtime=formatTime(this.list1[i].finputtime)
              // this.list1 = this.list1
                      
            }
          }
        } catch (err) {
          
        }
      };
      data();
    },
     },
     watch:{
       radio(e){
         if(e == '今天') {
           this.list1 =  this.timeOptions.filter(res=>{
             let format = new Date(res.finputtime).toDateString()
             let nowDate = new Date().toDateString()
             return format == nowDate
           })
         } else if (e == '本周') {

           let start = new Date()
           let end = new Date()
           let day = new Date().getDay() - 1
           let s = new Date(start.setTime(start.getTime() - 3600*24*1000*day))
           let e = new Date(end.setTime(start.getTime() + 3600*1000 *24 * 6))
        
           let sY = s.getFullYear()
           let sM = s.getMonth()
           let sD = s.getDate()
           let eY = e.getFullYear()
           let eM = e.getMonth()
           let eD = e.getDate()
           let nstart = new Date(sY,sM,sD)
           let nend = new Date(eY,eM,eD,'23','59','59')
           this.list1 = this.timeOptions.filter(res=>{
             let date = +new Date(res.finputtime)
             return date>= nstart && date <= nend
           })
         } else if (e == '本月') {
             this.list1 =  this.timeOptions.filter(res=>{
             let format = new Date(res.finputtime).getFullYear() + new Date(res.finputtime).getMonth() 
             let nowDate = new Date().getFullYear() + new Date().getMonth()
            return format == nowDate
           })
         } else {
           return console.log('超出日期')
         }
          return this.list1
       }
     }
}
</script>

<style scoped>
.all{
  height: 100%;
  border: 1px solid black
}
.body{
  height: 600px;
}
.head {
    height: 40px;
    margin: 20px 30px;
    display: flex;
    justify-content: space-between;
}
.table {
    width: 95%;
    margin-left: 40px;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between
}
.title {
    width: 150px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    
}
img {
    width: 50px;
    height: 50px;
    margin-right: 20px;
    border-radius: 50%;
}
</style>
